
package com.lry.rpc.netty;


public enum MsgType {

    RPC_REQUEST((byte)1,"rpc_request"),

    RPC_RESPONSE((byte)2,"rpc_response"),

    HEARTBEAT_REQUEST((byte)3,"heartbeat_request"),

    HEARTBEAT_RESPONSE((byte)4,"heartbeat_response");

    private final byte code;

    private final String name;

    MsgType(final byte code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getName(byte code){
        return getByCode(code).name;
    }

    /**
     * Gets result code.
     *
     * @param code the code
     * @return the result code
     */
    public static MsgType getByCode(int code) {
        for (MsgType b : MsgType.values()) {
            if (code == b.code) {
                return b;
            }
        }
        throw new IllegalArgumentException("unknown codec:" + code);
    }

    /**
     * Gets result code.
     *
     * @param name the name
     * @return the result code
     */
    public static MsgType getByName(String name) {
        for (MsgType b : MsgType.values()) {
            if (b.name().equalsIgnoreCase(name)) {
                return b;
            }
        }
        throw new IllegalArgumentException("unknown codec:" + name);
    }

    /**
     * Gets code.
     *
     * @return the code
     */
    public byte getCode() {
        return code;
    }
}
